function pageTurn(current_page, flag, pages, sum_id, type){
//    console.log(cur_page)
//    console.log(typeof cur_page)
//    console.log(sum_id)
//    console.log(typeof sum_id)
    var target_page = 0
    if(flag=="True"){
        console.log("True")
        target_page = current_page + 5
    }else{
        console.log("False")
        target_page = current_page - 5
    }
    if(target_page<1){
        target_page=1
    }else if(target_page > pages){
        target_page=pages
    }
    console.log(target_page)
    $.ajax({
//            url: `/detail/?type=${type}&sum_id=${sum_id}&page=${target_page}`,
            type: "GET",
            async : false,
            dataType:"html",//返回整合HTML
            contentType:'application/json; charset=utf-8',
            success: function (data) {
                window.location.href = '/detail/?type='+type+'&sum_id='+sum_id+'&page='+target_page;
            }
    })
}

function selectEvents(type, sum_id){
    var value=$("#TypeId option:selected").val();
    var condition=""
    console.log(value)
    if(value == "1"){
        condition="1"
    }else if(value=="2"){
        condition="0"
    }else if(value == "3"){
        condition="-1"
    }
    console.log(condition)
    $.ajax({
            type: "GET",
            async : false,
            dataType:"html",//返回整合HTML
            contentType:'application/json; charset=utf-8',
            success: function (data) {
                window.location.href = '/detail/?type='+type+'&sum_id='+sum_id+'&page=1'+'&condition='+condition;
            }
    })
}


function isCollapse(index){
    var collapse = document.getElementById("test-detail-"+index);
    var jiantou = document.getElementById("iconfont-"+index);
//    console.log(collapse.innerHTML)
    if(collapse.innerHTML == ""){
        data=collapse.title
        console.log(typeof data)
        console.log(data)
        if(data!=""){
            data=eval("("+data+")")
        }else{
            data=[]
        }
        console.log(data)
        collapse.innerHTML=`<td id='collapse-${index}' style='text-align: center;' colspan='10'><div style="display:flex; justify-content: center;">
        <div style="text-align: right; font-weight: 700;">请求方法：<br>请求链接：<br>请求参数：<br>关键参数值：<br>参数完整性：<br>特殊参数值：</div>
        <div style="text-align: left;">${data['request_method']}<br>${data['request_url']}<br>${data['request_params']}<br>待比较关键参数名称：${data['return_code']['return_code_to_compare']}，预期关键参数值：${data['return_code']['expect_return_code']}，实际关键参数值：${data['return_code']['actual_return_code']}<br>预期参数名称：${data['param_complete']['expect_params']}，实际参数名称：${data['param_complete']['actual_params']}<br>待比较特殊参数名称：${data['param_value']['param_to_compare']}，预期特殊参数值：${data['param_value']['expect_param_value']}，实际特殊参数值：${data['param_value']['actual_param_value']}</div>

        </div></td>`
        jiantou.innerHTML =  "&#xe622;"
    }else{
        collapse.innerHTML=""
        jiantou.innerHTML = "&#xe612;"
    }
}

function isHidden(index){
    var collapse = document.getElementById("test-summary-"+index);
    var jiantou = document.getElementById("iconfont-"+index);
//    console.log(collapse.innerHTML)
    if(collapse.innerHTML == ""){
        // 隐藏信息包括 用例总数、成功用例数、失败用例数，以及失败用例数中各个事件类型的个数
        data=collapse.title
        if(data!=""){
            data = JSON.parse(data)
        }else{
            data=[]
        }
        console.log(data)
        var string =""
        for(let i=0; i<data.length; i++){
            string=string+"事件类型："+data[i][0]+"，失败用例数："+data[i][1]+"</br>"
        }
        collapse.innerHTML=`<td id='collapse-${index}' style='text-align: center;' colspan='7'><div style='display:flex; justify-content: center;'><div style='font-weight: 700;'>未通过用例概述：</div><div style=''>${string}</div></div></td>`
        jiantou.innerHTML =  "&#xe622;"
    }else{
        collapse.innerHTML=""
        jiantou.innerHTML = "&#xe612;"
    }
}

function edit(index){
     var editButton = $('#edit'+index)
     var status = editButton.text()
     editButton.text(status==='确定'?'编辑':'确定')
     if(status == '编辑'){
        var remark = $('#remark'+index)
        console.log(remark)
        var text = remark.attr("title")
        console.log(text)
        remark.text('')
        if(! text){
            remark.append(`<input class='remarkInput-${index}' value='' />`)
        }else{
            remark.append(`<input class='remarkInput-${index}' value='${text}' />`)
        }
     }else{
        var remarkInput = $('.remarkInput-'+index)
        remarkInput.each(function(){
            var index = $(this).parent().attr('data-remark')
            var type = $(this).parent().attr("class").split(" ")[1]
            var value = $(this).val()
//            console.log(index)
//            console.log(type)
//            console.log(value)
            var remark = $('#remark'+index)
            console.log(`${value}`.length)
            if(`${value}`.length <= 20){
                remark.text("").append(`${value}`)
            }else{
                remark.text("").append(value.substring(0,17)).append("...")
            }
            remark.attr("title", `${value}`)
            $.ajax({
                url: `/saveRemark/?type=${type}&remark=${value}&id=${index}`,
                type: "GET",
                dataType: "json",
                success: function (data) {
                    console.log(data)
                }
            })
        })
     }
}

// 不再使用
function save(list){
    var remarkInput = $('.remarkInput')
    remarkInput.each(function(){
        var index = $(this).parent().attr('data-remark')
        var type = $(this).parent().attr("class").split(" ")[1]
        var value = $(this).val()
        console.log(index)
        console.log(type)
        console.log(value)
        var remark = $('#remark'+index)
        if(`${value}`.length <= 10){
            remark.text("").append(`${value}`)
        }else{
            remark.text("").append(value.substring(0,7)).append("...")
        }
        remark.attr("title", `${value}`)
        $.ajax({
            url: `/saveRemark/?type=${type}&remark=${value}&id=${index}`,
            type: "GET",
            dataType: "json",
            success: function (data) {
//                console.log(data)
            }
        })
    })
}